package com.lbb.mvc.view

import android.app.Activity
import com.lbb.mvc.dialog.LoadingCenterDialog
import com.lbb.mvc.dialog.LoadingTopDialog

class ProgressDialogController : AttachProgressDialogView {
    var activity: Activity? = null
    var progressTopDialog: LoadingTopDialog? = null
    var progressCenterDialog: LoadingCenterDialog? = null

    override fun onAttach(activity: Activity?) {
        this.activity = activity
    }

    override fun onDetach() {

    }

    override fun getProgressDialogView(): ProgressDialogView {
        return this
    }

    override fun showTopProgressDialog(s: String?, cancelable: Boolean?) {
        activity?.let {
            progressTopDialog.let {
                progressTopDialog = LoadingTopDialog(activity)
            }

            cancelable?.let { progressTopDialog?.setCancelable(it) }
            progressTopDialog?.let {
                it.title = s
                it.show()
            }
        }
    }

    override fun showCenterProgressDialog(s: String?, cancelable: Boolean?) {
        activity?.let {
            progressCenterDialog.let {
                progressCenterDialog = LoadingCenterDialog(activity)
            }

            cancelable?.let { progressCenterDialog?.setCancelable(it) }
            progressCenterDialog?.let {
                it.title = s
                it.show()
            }
        }
    }

    override fun dismissTopProgressDialog() {
        progressTopDialog?.dismiss()
    }

    override fun dismissCenterProgressDialog() {
        progressCenterDialog?.dismiss()
    }

    override fun dismissProgressDialog() {
        dismissTopProgressDialog()
        dismissCenterProgressDialog()
    }
}